<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        var month = prompt('请输入月份')
        if (isNaN(month)) {
            alert("请输入数字！")
        } else {
            month = parseInt(month)

            // if-else 通常用于范围判断  if(a>2 && a<10)
            // 一般if-else用于等值判断时，如果超过两个，就应该考虑用switch
            /*
            if(a===2){
                
            }else if(a===3){    

            }else{

            }
            */
            //switch通常用于等值判断，结构
            /*
            switch (key) {
                case 1:
                    break;
                case 2:
                    break;
                default:
                    break; //最后一个break可以省略
            }
            
            */
            switch (month) {
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                    console.log(month + '月有31天');
                    break
                case 2:
                    console.log(month + '月有28天');
                    break
                case 4:
                case 6:
                case 9:
                case 11:
                    console.log(month + '月有30天');
                    break
                default:
                    console.log('请输入正确的月份');
                    break
            }
        }

    </script>
</body>

</html>